public class Solution764 {
    public int orderOfLargestPlusSign(int n, int[][] mines) {
        if (mines.length==n*n){
            return 0;
        }
        int[][] f=new int[n][n];
        for (int[] mine : mines) {
            f[mine[0]][mine[1]]=1;
        }
        int[][] g1=new int[n][n];
        int[][] g2=new int[n][n];
        int[][] g3=new int[n][n];
        int[][] g4=new int[n][n];
        for (int i=0;i<n;i++){
            int cur=0;
            for (int j=0;j<n;j++){
                g1[i][j]=cur;
                if (f[i][j]==1){
                    cur=0;
                }else {
                    cur++;
                }
            }
            cur=0;
            for (int j=n-1;j>=0;j--){
                g2[i][j]=cur;
                if (f[i][j]==1){
                    cur=0;
                }else {
                    cur++;
                }
            }
        }
        for (int i=0;i<n;i++){
            int cur=0;
            for (int j=0;j<n;j++){
                g3[j][i]=cur;
                if (f[j][i]==1){
                    cur=0;
                }else {
                    cur++;
                }
            }
            cur=0;
            for (int j=n-1;j>=0;j--){
                g4[j][i]=cur;
                if (f[j][i]==1){
                    cur=0;
                }else {
                    cur++;
                }
            }
        }
        int max=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                if (f[i][j]!=1) {
                    max=Math.max(max,Math.min(Math.min(g1[i][j],g2[i][j]),Math.min(g3[i][j],g4[i][j])));
                }
            }
        }
        return max+1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution764().orderOfLargestPlusSign(5,new int[][]{{0,0},{0,3},{1,1},{1,4},{2,3},{3,0},{4,2}}));
    }
}
